{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "68e2990c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import math\n",
    "from tqdm import tqdm\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "format_data = {\n",
    "        \"device_id\":[],\n",
    "        \"cpu_id\":[],\n",
    "        \"record_id\":[],\n",
    "        \"timestamp\":[],\n",
    "        \"process_id\":[],\n",
    "        \"trace_action\":[],\n",
    "        \"operation_type\":[], #N操作的时候，没有扇区num，没有IOsize，只有进程name\n",
    "        \"sector_num\":[],\n",
    "        \"IO_size\":[],\n",
    "        \"process_name\":[]\n",
    "    }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a24a782c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(77342170, 1)\n",
      "                                                   0\n",
      "0  259,2    0        1     0.000000000  4020  Q  ...\n",
      "1  259,2    0        2     0.000001581  4020  G  ...\n",
      "2  259,2    0        3     0.000003650  4020  U  ...\n",
      "3  259,2    0        4     0.000003858  4020  I  ...\n",
      "4  259,2    0        5     0.000005462  4020  D  ...\n"
     ]
    }
   ],
   "source": [
    "def get_data():\n",
    "    data = pd.read_csv('../data_set/ssdtrace-00',delimiter ='\\t',header=None)\n",
    "    #data = pd.read_csv('../data_set/ssdtrace-sample',delimiter ='\\t',header=None)\n",
    "    return data   \n",
    "data = get_data()\n",
    "print(data.shape)\n",
    "print(data.head())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "3eaf99e9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "区间如下:\n",
      " 0 ~ 19335542\n",
      "19335542 ~ 38671084\n",
      "38671084 ~ 58006626\n",
      "58006626 ~ 77342170\n"
     ]
    }
   ],
   "source": [
    "cnt = data.shape[0]\n",
    "b1 = 0\n",
    "e1 = cnt//4\n",
    "b2 = e1\n",
    "e2 = b2+cnt//4\n",
    "b3 = e2\n",
    "e3 = b3 + cnt//4\n",
    "b4 = e3\n",
    "e4 = cnt\n",
    "print(\"区间如下:\\n\",b1,\"~\",e1)\n",
    "print(b2,'~',e2)\n",
    "print(b3,'~',e3)\n",
    "print(b4,'~',e4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e2df46b7",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_1 = data.iloc[b1:e1,:]\n",
    "data_2 = data.iloc[b2:e2,:]\n",
    "data_3 = data.iloc[b3:e3,:]\n",
    "data_4 = data.iloc[b4:e4,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "531518ac",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "map操作完成，数据集分成四份去处理\n"
     ]
    }
   ],
   "source": [
    "data_1.to_csv('../data_set/map-1.csv',header=None,index=False)\n",
    "data_2.to_csv('../data_set/map-2.csv',header=None,index=False)\n",
    "data_3.to_csv('../data_set/map-3.csv',header=None,index=False)\n",
    "data_4.to_csv('../data_set/map-4.csv',header=None,index=False)\n",
    "print(\"map操作完成，数据集分成四份去处理\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "627a02af",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                                                   0\n",
      "0  259,2    0        1     0.000000000  4020  Q  ...\n",
      "1  259,2    0        2     0.000001581  4020  G  ...\n",
      "2  259,2    0        3     0.000003650  4020  U  ...\n",
      "3  259,2    0        4     0.000003858  4020  I  ...\n",
      "4  259,2    0        5     0.000005462  4020  D  ...\n"
     ]
    }
   ],
   "source": [
    "test = pd.read_csv('../data_set/map-1.csv',delimiter ='\\t',header=None)\n",
    "print(test.head())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e8fc92f5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
